package com.yangxk.kadmin.generator.url.sub;

import com.yangxk.kadmin.generator.constant.Const;
import com.yangxk.kadmin.generator.url.Url;
import com.yangxk.kadmin.generator.url.UrlDesc;
import com.yangxk.kadmin.generator.util.Tools;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class AbstractUrl implements Url {

    protected static final String ADD = "/{0}/add";
    protected static final String EDIT = "/{0}/update";
    protected static final String DELETE = "/{0}/delete";
    protected static final String DETAIL = "/{0}/detail";

    protected static final String ADD_NAME = "添加";
    protected static final String EDIT_NAME = "修改";
    protected static final String DELETE_NAME = "删除";

    protected static final String ADD_CODE = "{0}:add";
    protected static final String EDIT_CODE = "{0}:update";
    protected static final String DELETE_CODE = "{0}:delete";

    private Map<String, String> urlMap = new HashMap<>();
    private Map<String, String> authCodeMap = new HashMap<>();

    protected String modelName;
    protected String zhModelName;


    protected void init() {
        initUrl();
        Map<String, String> map = addUrl();
        if (map != null)
            urlMap.putAll(map);

        initAuthCode();
        map = addAuthCode();
        if (map != null)
            authCodeMap.putAll(map);
    }

    private void initUrl() {
//        urlMap.put(Const.LIST_URL, Tools.formatStr(TREE, modelName));
        urlMap.put(Const.ADD_URL, Tools.formatStr(ADD, modelName));
        urlMap.put(Const.EDIT_URL, Tools.formatStr(EDIT, modelName));
        urlMap.put(Const.DELETE_URL, Tools.formatStr(DELETE, modelName));
        urlMap.put(Const.DETAIL_URL, Tools.formatStr(DETAIL, modelName));
        urlMap.put(Const.ROUTE, getRoute());
    }

    protected Map<String, String> addUrl() {

        return null;
    }

    protected void initAuthCode() {
        authCodeMap.put(Const.ADD_CODE, Tools.formatStr(ADD_CODE, modelName));
        authCodeMap.put(Const.EDIT_CODE, Tools.formatStr(EDIT_CODE, modelName));
        authCodeMap.put(Const.DELETE_CODE, Tools.formatStr(DELETE_CODE, modelName));
    }

    protected Map<String, String> addAuthCode() {

        return null;
    }

    @Override
    public Map<String, String> getRequestUrl() {
        return urlMap;
    }

    @Override
    public Map<String, String> getAuthCode() {
        return authCodeMap;
    }

    @Override
    public List<UrlDesc> getUrlDesc() {
        List<UrlDesc> result = new ArrayList<>();
//        result.add(new UrlDesc(Tools.formatStr(LIST, modelName), LIST_NAME, Tools.formatStr(LIST_CODE, modelName), true, Tools.formatStr(LIST, modelName)));
        result.add(new UrlDesc(Tools.formatStr(ADD, modelName), ADD_NAME, Tools.formatStr(ADD_CODE, modelName)));
        result.add(new UrlDesc(Tools.formatStr(EDIT, modelName), EDIT_NAME, Tools.formatStr(EDIT_CODE, modelName)));
        result.add(new UrlDesc(Tools.formatStr(DELETE, modelName), DELETE_NAME, Tools.formatStr(DELETE_CODE, modelName)));
        return result;
    }
}
